package test_value

import "fmt"

func Do() {
	fmt.Println("数据类型测试")
	//变量声明和初始化
	var a int
	a = 1
	var b = 2
	c := 3
	fmt.Println("变量声明和初始化 ", a, b, c)

	//未初始化前是零值
	var za int
	var zf float32
	var zb bool
	var zs string
	var zp *int
	var ze error
	fmt.Println("零值 ", za, zf, zb, zs, zp, ze)

	//多变量声明
	var v1, v2, v3 int
	v1, v2, v3 = 1, 2, 3
	var vvv1, vvv2, vvv3 = 111, 222, 333
	vv1, vv2, vv3 := 11, 22, 33
	fmt.Println("多变量声明 ", v1, v2, v3, vv1, vv2, vv3, vvv1, vvv2, vvv3)

	//全局变量（函数内全局）
	var (
		GLOBAL_1 = 1
		GLOBAL_2 = 2
	)
	fmt.Println("函数内访问函数内全局变量", GLOBAL_1, GLOBAL_2)

	//引用类型
	var p *int
	var num = 1
	p = &num
	fmt.Println("引用 ", num, &num, p, &p)

	//常量
	const CA, CB, CC = 111, 222, 333
	fmt.Println("常量测试 ", CA, CB, CC)
	const (
		ca = iota //0
		cb        //1
		cc        //2
		cd = "ha" //独立值，iota += 1
		ce        //"ha"   iota += 1
		cf = 100  //iota +=1
		cg        //100  iota +=1
		ch = iota //7,恢复计数
		ci        //8
	)
	fmt.Println("常量itoa测试 ", ca, cb, cc, cd, ce, cf, cg, ch, ci)
	fmt.Println("全局常量 ", CONST_A, CONST_B)

	//map
	fmt.Println("map测试")
	m1 := map[string]int{}
	m1["a"] = 1
	m1["b"] = 2
	fmt.Println(m1)
	delete(m1, "a")
	fmt.Println(m1)
	value_b, ok := m1["b"]
	fmt.Println(value_b, ok)
}

//访问包内全局
func testGlobal() {
	fmt.Println("包内访问全局变量", GLOBAL_A, GLOBAL_B)
}

//全局变量（包内全局，同时也导出了，包外可以通过包来访问）
var (
	GLOBAL_A = 1
	GLOBAL_B = 2
)

const (
	CONST_A = "A"
	CONST_B = "B"
)

var GLOBAL_C = 3

const CONST_C = "C"
